package com.xuelang.pipeline.client.pipeline;

import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.dto.PipelineInstanceConfigDTO;
import com.xuelang.pipeline.client.pipeline.dto.PipelineInstanceDTO;
import com.xuelang.pipeline.client.pipeline.dto.PipelineInstanceQuery;
import com.xuelang.pipeline.client.pipeline.dto.TriggerPipelineDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import jakarta.validation.Valid;
import java.util.List;

/**
 * <p>流水线实例服务API接口定义</p>
 *
 * @author : yixin.lys
 * @date : 2024-06-26 09:31
 **/
public interface IPipelineInstanceService {

    /**
     * 根据流水线code分页获取流水线实例
     *
     * @param dtoPageParam
     * @return
     */
    @PostMapping(value = "/page", produces = "application/json;charset=utf-8")
    PageRecord<PipelineInstanceDTO> page(@RequestBody @Valid PageParam<PipelineInstanceQuery> dtoPageParam);

//    /**
//     * 根据流水线配置态编码获取流水线运行态实例
//     * 这个接口给流水线保存并运行后调转的时候调用，这个时候还没有流水线实例
//     * @param pipelineCode
//     * @return
//     */
//    @GetMapping(value = "/pipelineInstance/info/{pipelineCode}", produces = "application/json;charset=utf-8")
//    ApiResult<PipelineInstanceConfigDTO> getPipelineInstanceByPipelineCode(@PathVariable("pipelineCode") String pipelineCode);

    /**
     * 根据流水线实例或者流水线配置获取流水线运行态实例
     *
     * @param code
     * @return
     */
    @GetMapping(value = "/info/{flag}/{code}", produces = "application/json;charset=utf-8")
    ApiResult<PipelineInstanceConfigDTO> getPipelineInstance(@PathVariable("flag") String flag, @PathVariable("code") String code);

    /**
     * 根据流水线code触发流水线
     *
     * @param triggerPipelineDTO
     * @return
     */
    @PostMapping(value = "trigger/pipeline", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> triggerPipeline(@RequestBody @Valid TriggerPipelineDTO triggerPipelineDTO);

    /**
     * 根据流水线code集合 批量触发流水线
     *
     * @param pipelineCodeList
     * @return
     */
    @PostMapping(value = "trigger/batch/pipeline", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> batchTriggerPipeline(@RequestBody @Valid List<String> pipelineCodeList);

    /**
     * 根据流水线code取消/停止流水线
     *
     * @param pipelineCode
     * @return
     */
    @PostMapping(value = "cancel/pipeline/{code}", produces = "application/json;charset=utf-8")
    ApiResult<Boolean> cancelPipeline(@PathVariable("code") String pipelineCode);

    /**
     * 审批人工卡点
     *
     * @param type
     * @param taskInstanceCode
     * @return
     */

    @PostMapping(value = "/approve/{type}/{taskInstanceCode}")
    ApiResult<Boolean> instanceApprove(@PathVariable("type") String type,
                                       @PathVariable("taskInstanceCode") String taskInstanceCode);
}
